package com.qf.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.qf.aop.annocation.LoginToken;
import com.qf.entity.Address;
import com.qf.entity.ResultEntity;
import com.qf.entity.User;
import com.qf.service.IAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/address")
@Slf4j
public class AddressController {

    @Autowired
    private IAddressService addressService;

    @RequestMapping(value = "/getAddressListByUid/{uid}")
    public List<Address> getAddressListByUid(@PathVariable Integer uid){
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq("uid",uid);
        List list = addressService.selectList(entityWrapper);
        log.info(list.size()+"");
        return list;
    }

    @RequestMapping("/insertAddress")
    @LoginToken
    public ResultEntity insertAddress(User user, Address address){
        address.setUid(user.getId());
        return  ResultEntity.success( addressService.insertAddress(address));
    }

    @RequestMapping("/getAddressById/{aid}")
    public Address getAddressById(@PathVariable  Integer aid){
        return  addressService.selectById(aid);
    }
}
